from sqlalchemy import Column, Integer, String, Text, DateTime, func
from core.database import Base



class OfficialContact(Base):
    __tablename__ = 'official_contact'

    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(100), nullable=False, comment='姓名')
    phone = Column(String(20), nullable=False, unique=True, comment='电话')  # 添加 unique=True
    description = Column(Text, nullable=True, comment='需求描述')
    created_at = Column(DateTime, default=func.now(), nullable=False, comment='创建时间')
    updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), nullable=False, comment='更新时间')

    def __repr__(self):
        return f"<OfficialContact(id={self.id}, name='{self.name}', phone='{self.phone}')>"


    def to_dict(self):
        # 将模型转换为字典，便于JSON序列化
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}